﻿using FDSimpleModelGenerator.DapperAccessor;
using FDSimpleModelGenerator.IServices;
using Microsoft.Extensions.DependencyInjection;

namespace FDSimpleModelGenerator.Services.MySql
{
    /// <summary>
    /// MySql生成数据库表服务接口
    /// </summary>
    public static class MySqlGeneratorExtensions
    {
        /// <summary>
        /// 使用My Sql生成器
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddMySqlGenerator(this IServiceCollection services)
        {
            // 以防止多次注入DapperDbAccessor
            services.Remove(new ServiceDescriptor(typeof(IDbAccessor), typeof(DapperDbAccessor),
                ServiceLifetime.Transient));
            services.AddTransient<IDbAccessor, DapperDbAccessor>();
            services.AddTransient<IDbConfigResolver, MySqlDbConfigResolver>();
            services.AddSingleton<IGenerateModelService, GenerateModelMySqlService>();
            services.AddTransient<IDatabaseTableInfoService, MySqlDatabaseTableInfoService>();
            services.AddTransient<IGenerateTableService, MySqlGenerateTableService>();
            return services;
        }
    }
}
